

public class SingleDemo {

}

/*饿汉式*/
class ImageLoader {
    private static ImageLoader load = new ImageLoader();
    private ImageLoader(){};
    public static ImageLoader getInttance(){
        return load;
    }

}

/*懒汉式*/
class LazySingleDemo {
    private static LazySingleDemo lazy;
    private LazySingleDemo() {};
    public static synchronized LazySingleDemo getInstance() {
        if (lazy == null) {
            lazy = new LazySingleDemo();
        }
        return lazy;
    }
}

/*双重锁机制*/
class DclDemo {
    private static volatile DclDemo dcl;
    private DclDemo() {};
    public static DclDemo getInstance() {
        if (dcl == null) {
            synchronized (DclDemo.class) {
                if (dcl == null) {
                    dcl = new DclDemo();
                }
            }
        }
        return dcl;
    }
}

/*静态内部类*/
class StaticSingle {
    private static class inner {
        private static final StaticSingle single = new StaticSingle();
    }
    private StaticSingle() {
    }
    private static StaticSingle getInstance() {
        return inner.single;
    }
}


